/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Data;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author NGOCLINH-PC
 */
public class About {

    int AboutID;
    String AboutName;
    String AboutContent;
    int Role;
    int Status;

    public About() {
    }

    public About(int AboutID, String AboutName, String AboutContent, int Role, int Status) {
        this.AboutID = AboutID;
        this.AboutName = AboutName;
        this.AboutContent = AboutContent;
        this.Role = Role;
        this.Status = Status;
    }

    public int getAboutID() {
        return AboutID;
    }

    public void setAboutID(int AboutID) {
        this.AboutID = AboutID;
    }

    public String getAboutName() {
        return AboutName;
    }

    public void setAboutName(String AboutName) {
        this.AboutName = AboutName;
    }

    public String getAboutContent() {
        return AboutContent;
    }

    public void setAboutContent(String AboutContent) {
        this.AboutContent = AboutContent;
    }

    public int getRole() {
        return Role;
    }

    public void setRole(int Role) {
        this.Role = Role;
    }

    public int getStatus() {
        return Status;
    }

    public void setStatus(int Status) {
        this.Status = Status;
    }

    public ArrayList<About> Cselect() {
        try {
            ArrayList<About> listCate = new ArrayList<About>();
            Statement st = Connect.Connect.getCon().createStatement();
            ResultSet rs = st.executeQuery("SELECT * FROM About where Roles=1");
            while (rs.next()) {
                About cate = new About(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getInt(4), rs.getInt(5));
                listCate.add(cate);// 
            }
            return listCate;
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    public ArrayList<About> selectContact() {
        try {
            ArrayList<About> listCate = new ArrayList<About>();
            Statement st = Connect.Connect.getCon().createStatement();
            ResultSet rs = st.executeQuery("SELECT * FROM About where Roles=2");
            while (rs.next()) {
                About cate = new About(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getInt(4), rs.getInt(5));
                listCate.add(cate);// 
            }
            return listCate;
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    public static void update(int id, String name, String content, int Status) {
        try {
            PreparedStatement st = Connect.Connect.getCon().prepareStatement("update About SET AboutName=?,AboutContent=?,Status=? WHERE AboutID=?");
            st.setString(1, name);
            st.setString(2, content);
            st.setInt(3, Status);
            st.setInt(4, id);
            ResultSet rs = st.executeQuery();
            if (rs.next()) {
                JOptionPane.showMessageDialog(null, "Update Successful!");
                //response.sendRedirect("DangKi.jsp");
            } else {
                JOptionPane.showMessageDialog(null, "Error!");
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Category.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
